package com.health.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.common.Result;
import com.health.entity.Disease;
import com.health.entity.pojo.PageData;
import com.health.entity.pojo.dto.QueryDiseaseDTO;
import com.health.entity.pojo.vo.DiseaseVO;
import com.health.service.IDiseaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fengjiaxing
 * @since 2023-04-15
 */
@RestController
@RequestMapping("/disease")
public class DiseaseController extends BaseController{


    @Autowired
    private IDiseaseService diseaseService;

    //查询疾病的分页数据
    @PostMapping("/getPageAll/{PageNum}/{PageSize}")
    public Result<Disease> getPageAll(@PathVariable("PageNum") Integer PageNum ,@PathVariable("PageSize") Integer PageSize , @RequestBody QueryDiseaseDTO queryDiseaseDTO){
       PageData pageData =  diseaseService.getDiseaseByPage(PageNum,PageSize,queryDiseaseDTO);
       return this.dataResult(pageData);
    }
    //单选删除疾病功能
    @DeleteMapping("/deleteDisease/{id}")
    public Result<Disease> deleteDisease(@PathVariable("id") Integer id){
        boolean b = diseaseService.removeById(id);
        return Result.success(200,"删除成功",b);
    }

    //多选删除
    @PostMapping("/deleteSelectDisease")
    public Result<Disease> deleteSelectDisease(@RequestBody List<Integer> ids){
     boolean deleteSelect = diseaseService.deleteSelectDisease(ids);
     return Result.success(200,"多选删除成功",deleteSelect);
    }

    //新增疾病
    @PostMapping("/addDisease")
    public Result<Disease> addDisease(@RequestBody Disease disease){
        boolean b = diseaseService.saveOrUpdate(disease);
        return Result.success(200,"新增成功!",b);
    }

    //根据id获取疾病信息
    @GetMapping("/getDisease/{id}")
    public Result<Disease> getDisease(@PathVariable("id") Integer id){
        Disease disease = diseaseService.getById(id);
        return Result.success(200,"成功查询编辑疾病的数据显示",disease);
    }


}
